<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<%@ include file="/WEB-INF/jsp/inc/taglibs.jsp"%>
	<%@ include file="/WEB-INF/jsp/inc/meta.jsp"%>
	<script type="text/javascript" src="${approot}/resource/jquery/validate/jquery.validate.js"></script>
   <link href="${approot}/resource/jquery/validate/jquery.validate.css" rel="stylesheet" type="text/css" />
   <link href="${approot}/resource/jquery/validate/style.css" rel="stylesheet" type="text/css" />
     <script type="text/javascript">
            /* <![CDATA[ */
            jQuery(function(){
            	
               
                jQuery('#excerpt').validated(function(){
					alert("通过验证");
					do_pay_money();
				});
            });
            /* ]]> */
        </script>
        
        <script type="text/javascript">
        function do_pay_money()
        {   
            var str=$('#excerpt').serializeObject();
            var jsons = $.toJSON(str);
            
            pay_money(jsons);
        }


        function pay_money(jsons){
        	var str;
        	var payWise;
            if(document.getElementById('payWise_1').checked == true){
            	str = '您确认以【现金缴费】的方式处理本次操作吗?';
            	payWise = 0;
            }else if(document.getElementById('payWise_2').checked == true){
            	str = '您确认以【气票缴费】的方式处理本次操作吗?';
            	payWise = 1;
            }else if(document.getElementById('payWise_3').checked == true){
            	str = '您确认以【卡扣费】的方式处理本次操作吗?';
            	payWise = 2;
            	if(document.getElementById('card_number').value==''){
            		alert('您选择了【卡扣费】方式缴费，卡号不能为空');
            		return false;
            	}
            	if(parseFloat(document.getElementById('residual_money').value) < parseFloat(document.getElementById('gas_money').value)){
            		alert('您当前账户余额不足，请充值。');
            		return false;
            	}
            }else{
            	alert('系统异常');
            	return false;
            }
            var excerptId = document.getElementById('excerpt_id').value;
            var cardId = document.getElementById('card_id').value;
            var cardNumber = document.getElementById('card_number').value;
        	if(confirm(str)){
        		$.ajax({
		 		   	url:'${approot}/admin/excerpt/pay_money/'+excerptId+'/'+cardId+'/'+cardNumber+'/'+payWise,
		 		   	dataType: 'json',
		 		   	contentType: 'application/json',
		 			data:null,
		 			type:'post',
		 			beforeSend:function(){
		 			  // $('#main').disabled='true';
		 			},
		 			error:function(request){
		 				alert(S);
		 			},
		 			success:function(data){
		 			   if(data.msg=="error")
		 			   {
		 	 			   alert('缴费失败');
		 			   }
		 			   if(data.msg=="succ")
		 			   {
		 				  alert('缴费成功');
		 				  window.location.reload();
		 			   }
		 			}
		 		   });
        	}
 	    
 	}
 	
 	function show_card_number(number){
 		$.ajax( {
			url : '${approot}/admin/excerpt/get_card_list/' + number,
			dataType : 'json',
			contentType : 'application/json',
			data : null,//$.toJSON({'id':id}),
			type : 'post',
			beforeSend : function() {
				// $('#main').disabled='true';
			},
			error : function(request) {
				//alert(S);
			},
			success : function(data) {
				if (data.msg == "error") {
					alert('系统异常，获取用户卡列表失败');
				}
				if (data.msg == "succ") {
				}
				var popUp = document.getElementById("popupcontent");
				popUp.style.left = "100px";
				popUp.style.width = 600 + "px";
				popUp.innerHTML = data.sb.toString();
				popUp.style.visibility = "visible";
				document.getElementById('show_card_list').style.display = 'block';

		}
		});
 	}
 	
 	function hidePopup(){
		var popUp = document.getElementById("popupcontent");
		popUp.style.visibility = "hidden";
		popUp.innerHTML = "";
	}
	
	function hidePopupOther(){
		document.getElementById('card_id').value = '';
 		document.getElementById('card_number').value = '';
 		document.getElementById('residual_money').value = '';
 		document.getElementById('show_card_list').style.display = 'none';
 		
		var popUp = document.getElementById("popupcontent");
		popUp.style.visibility = "hidden";
		popUp.innerHTML = "";
	}
	
	function set_card_number(cardId,cardNumber,residualMoney){
		document.getElementById('card_id').value = cardId;
		document.getElementById('card_number').value = cardNumber;
		document.getElementById('residual_money').value = residualMoney;
	}
        </script>
   
</head>  
  <body style="background:#E8F5FE; padding:15px 18px;" class="scroll_r">
<div id="right_w"><p>当前位置：收费管理 >>客户缴费</p></div>

<form method="post" action="${approot}/admin/excerpt/pay_money" id="excerpt">
  <table border="0" cellpadding="0" cellspacing="1" width="92%" align="center" class="tab_l">
    <tr>
      <td><b>请按要求填写：</b></td>
      <td align="right">带<span style="color:#ff0000;">*</span>为必填</td>
    </tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="1" width="92%" align="center" id="add_tab">
  <tr>
   <th>编号：<input type="hidden" name="" value="${excerpt.excerptId }" id="excerpt_id" ></th>
   <td><input type="text" name="" value="${excerpt.personNumber }" id="" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td>
 
   <th width="20%">姓名：</th>
   <td width="30%"><input type="text" id="" name="" value="${excerpt.personName }" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 
  </tr>
   <tr>
   <th width="20%">地址：</th>
   <td width="30%"><input type="text" id="" name="" value="${excerpt.address }" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 

   <th width="20%">燃气类型：</th>
   <td width="30%"><input type="text" id="" name="" value="<c:if test="${excerpt.gasType==0}">天然气</c:if><c:if test="${excerpt.gasType==1}">液化气</c:if><c:if test="${excerpt.gasType==2}">商业气</c:if>" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 
  </tr>
   <tr>
   <th width="20%">读数：</th>
   <td width="30%"><input type="text" id="" name="" value="${excerpt.readAmount }" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 

   <th width="20%">气量：</th>
   <td width="30%"><input type="text" id="" name="" value="${excerpt.gasAmount }" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 
  </tr>
   <tr>
   <th width="20%">气费：</th>
   <td width="30%"><input type="text" id="gas_money" name="" value="${excerpt.gasMoney }" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 

   <th width="20%">电话：</th>
   <td width="30%"><input type="text" id="" name="" value="${excerpt.personPhone}" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 
  </tr>
  <tr>
   <th width="20%">抄表时间：</th>
   <td width="80%" colspan="3"><input type="text" id="" name="" value="<fmt:formatDate value="${excerpt.excerptTime}"
									pattern="yyyy-MM-dd HH:mm:ss" />" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 
  </tr>
  <tr>
  
   <td width="80%" colspan="4">&nbsp;</td> 
  </tr>
  <tr>
   <th width="20%">付费状态：</th>
   <td width="80%" colspan="3"><input type="text" id="" name="" value="<c:if test="${excerpt.payStatus == 0}">未缴费</c:if><c:if test="${excerpt.payStatus == 1}">已缴费</c:if>" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 
  </tr>
  <c:if test="${excerpt.payStatus == 1}">
  <tr>
   <th width="20%">付费方式：</th>
   <td width="80%" colspan="3"><input type="text" id="" name="" value="<c:if test="${excerpt.payWise == 0}">现金缴费</c:if><c:if test="${excerpt.payWise == 1}">气票缴费</c:if><c:if test="${excerpt.payWise == 2}">卡扣费</c:if>" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 
  </tr></c:if>
  <c:if test="${excerpt.payStatus == 0}">
  <tr>
   <th width="20%">付费方式：</th>
   <td width="80%" colspan="3">
<input type="radio" name="payWise" id="payWise_1" value="0" checked="checked" onclick="hidePopupOther();">现金缴费	 
<input type="radio" name="payWise" id="payWise_2" value="1" onclick="hidePopupOther();">气票缴费
<input type="radio" name="payWise" id="payWise_3" value="2" onclick="show_card_number(${excerpt.personNumber});">卡扣费
</td> 

  </tr>
  
   <tr id="show_card_list" style="display: none">
   <th width="20%">卡号：<input type="hidden" name="" id="card_id" value=""/></th>
   <td width="30%"><input type="text" id="card_number" name="" value="" readonly="readonly"></td> 
   <th width="20%">余额：</th>
   <td width="30%"><input type="text" id="residual_money" name="" value="" readonly="readonly"><span style="color:#ff0000; margin:0;">*</span></td> 
  
  </tr>
<tr><td colspan="4" align="center"> <div id="popupcontent"></div></td></tr>
  </c:if>
 
 </table>
  <c:if test="${excerpt.payStatus == 0}">  <p id="tab_but">
  
 <input type="button" value="缴 费" onclick="pay_money();"></p></c:if>
</form>
</body>
</html>
